// 新增显示
function showInsertVal() {
    $("#updateId").hide();
    if ($("#savaId").is(":hidden")) {
        $("#savaId").show();
    } else {
        $("#savaId").hide();
    }
    var level = $('#menuLevel option:selected').val();
    // ajax调用调查询级别数据
    if (level != 0) {
        $("#SecondSel").show();
    } else {
        $("#SecondSel").hide();
    }
}

function saveMenu() {
    var status = $("input[name='addButtonStatus']:checked").val();
    if (Number(status) != 0 && Number(status) != 1){
        layer.msg("请配置该菜单页面是否拥有基础按钮,比如查询、修改等功能!", {icon: 6, time: 3000}, function () {
        });
        return;
    }

    var parentId = 0;
    var level = $('#menuLevel option:selected').val();
    if (level != 0) {
        if (sessionStorage.getItem("menuId") != null) {
            parentId = sessionStorage.getItem("menuId");
        } else {
            layer.msg("请在菜单树上选择要增加菜单的上级!", {icon: 6, time: 3000}, function () {
            });
            return;
        }
    }
    if (parentId.length == 16){
        layer.msg("基础按钮不可配置下级菜单!", {icon: 6, time: 3000}, function () {
        });
        return;
    }

    if ($("#menuName").val() == null || $("#menuName").val() == '' || $("#menuName").val() == undefined){
        layer.msg("名称不能为空!", {icon: 6, time: 3000}, function () {
        });
        return;
    }

    var user_data = {
        "parentId" : parentId,
        "menuName" : $("#menuName").val(),
        "buttonStatus" : status
    }
    var succCallBack = function(data, status, response) {
        console.log(data)
        window.location.reload();
        /*var index =  parent.location.reload();
        parent.layer.close(index);*/
    }
    web.doAjax(root.accessInter.access_menu_save, 'post', user_data, succCallBack);
}

function showUpdateVal() {
    if (sessionStorage.getItem("menuId") != null && sessionStorage.getItem("menuName") != null
            && sessionStorage.getItem("buttonStatus") != null ) {
        var menuName = sessionStorage.getItem("menuName");
        var name = menuName.split("|");
        $("#updateMenuName").val(name[1]);
    } else {
        layer.msg("请先选中要修改的菜单!", {icon: 6, time: 3000}, function () {
        });
        return
    }

    $("#savaId").hide();
    if ($("#updateId").is(":hidden")) {
        $("#updateId").show();
    } else {
        $("#updateId").hide();
    }
    /*修改radio默认选中*/
    var status = sessionStorage.getItem("buttonStatus");
    if (Number(status) == 1){
        $("#buttonStatusY").prop("checked",true);
        $("#buttonStatusN").prop("checked",false);
    } else {
        $("#buttonStatusN").prop("checked",true);
        $("#buttonStatusY").prop("checked",false);
    }
}

function upateMenu() {
    var status = $("input[name='upButtonStatus']:checked").val();
    if (Number(status) != 0 && Number(status) != 1){
        layer.msg("请配置该菜单页面是否拥有基础按钮,比如查询、修改等功能!", {icon: 6, time: 3000}, function () {
        });
        return;
    }

    var parentId = sessionStorage.getItem("menuId");
    if (parentId.length == 16){
        layer.msg("基础按钮不可修改!", {icon: 6, time: 3000}, function () {
        });
        return;
    }

    var menuName = $("#updateMenuName").val();
    if (menuName == null || menuName == '' || menuName == undefined){
        layer.msg("修改名称不能为空!", {icon: 3, time: 3000}, function () {
        });
        return
    }
    var date = {
        menuId : parentId,
        menuName : menuName,
        buttonStatus : status
    }

    var succCallBack = function(data, status, response) {
        console.log(data)
        window.location.reload();
        /*var index =  parent.location.reload();
        parent.layer.close(index);*/
    }

    web.doAjax(root.accessInter.access_menu_update, 'post', date, succCallBack);
}


function deleteMenuVal() {
    if (sessionStorage.getItem("menuId") == null) {
        layer.msg("请先选中要修改的菜单!", {icon: 6, time: 1000}, function () {
        });
        return
    }
    if (sessionStorage.getItem("menuId").length == 16){
        layer.msg("基础按钮不可删除!", {icon: 6, time: 3000}, function () {
        });
        return
    }
    var date = {
        menuId : sessionStorage.getItem("menuId")
    }

    var succCallBack = function(data, status, response) {
        if (data.errorCode == 0){
            layer.msg("删除成功", {icon: 6, time: 1000}, function () {
            });
            window.location.reload();
        } else {
            layer.msg(data.errorMessage, {icon: 6, time: 1000}, function () {
            });
        }
    }

    web.doAjax(root.accessInter.access_menu_delete, 'post', date, succCallBack);
}

function resh() {
    window.location.reload();
}